cmake_minimum_required(VERSION 3.15)
project(al)

# 设置c++规范
set(CMAKE_CXX_STANDARD 20)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

# if (WIN32)
#     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
# endif()


# if (MINGW OR MSYS)
#     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libgcc -static-libstdc++")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libgcc -static-libstdc++")
# endif()

# 包含头文件以及外部头文件
if(MINGW)
include_directories(
    ${PROJECT_SOURCE_DIR}/libs/raylib-5.5_win64_mingw-w64/include
    ${PROJECT_SOURCE_DIR}/includes
)
elseif(MSVC)
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
include_directories(
    ${PROJECT_SOURCE_DIR}/libs/raylib-5.5_win64_msvc16/include
    ${PROJECT_SOURCE_DIR}/includes
)
endif()

add_definitions(-DWIN32_LEAN_AND_MEAN -DNOMINMAX -DNOGDI)


# 收集所有可执行文件
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
    "src/*.cpp"
    "src/*.c" 
    LIST_DIRECTORIES false
)

# 匹配静态库
if(MINGW)
find_library(RAYLIB_LIB 
    NAMES 
        libraylib           #名字对应的动态库或者静态库
        libraylibdll        
        raylib    
    PATHS ${PROJECT_SOURCE_DIR}/libs/raylib-5.5_win64_mingw-w64/lib
    REQUIRED
)
elseif(MSVC)
find_library(RAYLIB_LIB 
    NAMES 
        raylib           #名字对应的动态库或者静态库
        raylibdll        
        # raylib    
    PATHS ${PROJECT_SOURCE_DIR}/libs/raylib-5.5_win64_msvc16/lib
    REQUIRED
)
endif()


# 添加收集到的文件为可执行文件编译
add_executable(maze ${SRC_FILES})
# 链接之前获取到的库
target_link_libraries(maze 
    ${RAYLIB_LIB} 
    opengl32 imm32 winmm
)

# examples示例代码快速构建
# 匹配examples中的源文件
file(GLOB_RECURSE EXM_FILES CONFIGURE_DEPENDS
    "examples/*.cpp"
    LIST_DIRECTORIES false
)
# # 为每个example源文件创建可执行文件
foreach(source_file ${EXM_FILES})
    # 获取不带扩展名的文件名
    get_filename_component(program_name ${source_file} NAME_WE)
    # 创建可执行文件
    add_executable(${program_name} ${source_file})
    # 链接库
    target_link_libraries(${program_name} ${RAYLIB_LIB} winmm imm32 opengl32)
endforeach()

# 将资源复制到build中
file(COPY assets DESTINATION ${CMAKE_CURRENT_BINARY_DIR})